package com.toutiao.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.base.action.CoreController;
import com.base.dao.model.Grid;
import com.base.dao.model.Ret;
import com.base.dialect.PaginationSupport;
import com.base.util.JSONUtils;
import com.base.web.annotation.LoginFilter;
import com.toutiao.dao.model.RechargeOrder;
import com.toutiao.dao.model.RechargeOrderExample;
import com.toutiao.service.RechargeOrderService;

@RequestMapping("rechargeOrder")
@Controller
@LoginFilter
public class RechargeOrderController extends CoreController{

	@Autowired
	private RechargeOrderService rechargeOrderService;

	@RequestMapping("/list")
	@ResponseBody
	public String list(Integer page, Integer rows){
		PaginationSupport.byPage(page, rows);
		RechargeOrderExample example = new RechargeOrderExample();
		List<RechargeOrder> list = rechargeOrderService.selectByExample(example);
		return JSONUtils.serialize(new Grid(PaginationSupport.getContext().getTotalCount(), list));
	}

	@RequestMapping("/save")
	@ResponseBody
	public String save(RechargeOrder rechargeOrder){
		if (rechargeOrder.getId() == null){
			rechargeOrderService.insert(rechargeOrder);
		}else{
			rechargeOrderService.updateByPrimaryKeySelective(rechargeOrder);
		}
		return JSONUtils.serialize(new Ret(0));
	}

	@RequestMapping("/findById")
	@ResponseBody
	public String find(Integer id){
		RechargeOrder rechargeOrder = rechargeOrderService.selectByPrimaryKey(id);
		return JSONUtils.serialize(rechargeOrder);
	}

	@RequestMapping("/del")
	@ResponseBody
	public String del(String id){
		String[] ids = id.split(",");
		for (String str : ids){
			rechargeOrderService.deleteByPrimaryKey(Integer.parseInt(str));
		}
		return JSONUtils.serialize(new Ret(0));
	}

}